import { defineConfig } from 'vite';
import uni from '@dcloudio/vite-plugin-uni';
import path from 'path';
import Unocss from "unocss/vite";
import CONFIG from './src/config.mjs';

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [uni(), Unocss()],
  server: {
    // port: 8080,
    host: '0.0.0.0',
    proxy: {
      '/api/': {
        target: CONFIG.LOCATION_ORIGIN,
        changeOrigin: true,
        rewrite: (p) => p.replace(/^\/api/, ''),
      },
    },
  },
  resolve: {
    alias: {
      '@': path.resolve(__dirname, './src'),
      '@components': path.resolve(__dirname, './src/components'),
    },
  },
  css: {
    // 配置`scss`和`less`全局变量
    preprocessorOptions: {
      scss: {
        additionalData: '@import "@/styles/vars/_base.scss";',
      },
      less: {
        additionalData: '@import "@/styles/vars/_base.less";',
      },
    },
  },
});
